<?php

function auth() {
  $CI = get_instance();
  log_message('debug', "Login function starting.");
  $login = $CI->db_session->userdata('logged_in');
  if($login == FALSE) {
    log_message('debug', "Session 'logged_in == FALSE, redirecting to login function");
    redirect("login");
  }
}

function check() {
  log_message('debug', "Auth Check function starting.");
  $CI = get_instance();
  $login = $CI->db_session->userdata('logged_in');
  $client = $CI->db_session->userdata('server_client_id');
  $username = $CI->db_session->userdata('user_system_user_name');
  if($login == FALSE) {
    log_message('debug', "Session 'logged_in == FALSE, redirecting to login function");
    redirect("login");
  }
  elseif($client != 0) {
    log_message('info', "Session is a client user. Access to this controller is FORBIDDEN!");
    $CI->db_session->destroy();
    log_message('info', "User forcefully logged out.");
    redirect("authfail");
  }
  else {
    return;
  }
}


?>